package tesis.common.security;

import javax.inject.Inject;
import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component("customPasswordEncoder")
public class CustomPasswordEncoder implements PasswordEncoder {

    @Inject
    private SeguridadService seguridadService;

    @Override
    public String encodePassword(String rawPass, Object salt) throws DataAccessException {
        return seguridadService.encriptar((String) salt, rawPass);
    }

    @Override
    public boolean isPasswordValid(String encPass, String rawPass, Object salt) throws DataAccessException {
        return seguridadService.encriptar((String) salt, rawPass).equals(encPass);
    }
}
